import { View, Text, Picker } from "@tarojs/components";
import { AtList, AtListItem, AtButton, AtMessage } from "taro-ui";
import { useState, useEffect } from "react";
import { getWarnbyuserApi } from "../../../utils/api";
import Taro, { useDidShow, useRouter } from "@tarojs/taro";
import { formatTime2 } from "../../../utils/to";
const detect_result = {
  1: "待完成",
  2: "正常",
  3: "蚁情",
  4: "入侵",
  5: "低电量",
  9: "其他"
};
const comfirm_result = {
  1: "未确认",
  2: "已处理",
  3: "误报"
};
const Index = () => {
  const router = useRouter();

  const [detailInfo, set_detailInfo] = useState({});

  useDidShow(() => {
    getInfo();
  });

  // 获取探测数据
  const getInfo = async () => {
    const res = await getWarnbyuserApi({
      confirm_res: 0,
      warn_type: 0,
      get_count: 1000,
      start_index: 0
    });
    if (res.res === 0) {
      set_detailInfo(res.records);
      // console.log(router.params.id);
      res.records.forEach(item => {
        // console.log(item);
        if (item.warn_id == router.params.id) {
          set_detailInfo(item);
        }
      });
    } else {
      Taro.atMessage({
        message: res.msg,
        type: "warning"
      });
    }
  };

  const onSubmit = () => {
    console.log(detailInfo);
    Taro.navigateTo({
      url: `/pages/packageb/inspect_add/index?project_name=${detailInfo.project_name}&project_id=${detailInfo.project_id}&point_name=${detailInfo.point_name}&point_id=${detailInfo.point_id}&warn_id=${detailInfo.warn_id}`
    });
  };

  return (
    <View className="detect-detail">
      <AtListItem title="所属工程" extraText={detailInfo.project_name} />
      <AtListItem title="布点名称" extraText={detailInfo.point_name} />
      <AtListItem title="布点标签" extraText={detailInfo.point_tag} />
      <AtListItem
        title="报警类型"
        extraText={detect_result[detailInfo.warn_type]}
      />
      <AtListItem
        title="确认结果"
        extraText={comfirm_result[detailInfo.confirm_res]}
      />
      <AtListItem
        title="确认时间"
        extraText={formatTime2(detailInfo.confirm_timestamp * 1000)}
      />
      <AtListItem title="确认人员" extraText={detailInfo.confirm_user_name} />
      <AtListItem
        title="探测时间"
        extraText={formatTime2(detailInfo.detect_timestamp * 1000)}
      />

      <AtButton type="primary" onClick={onSubmit}>
        新建检查
      </AtButton>
    </View>
  );
};

export default Index;
